package com.ss.ttvideoengine.c;

import android.os.Handler;
import android.os.Message;

import com.ss.ttvideoengine.d.TTVideoError;

import java.lang.ref.WeakReference;

public class a {
    final static class WeakHandler extends Handler {
        private final WeakReference<a> aRef;

        public WeakHandler(a arg2) {
            this.aRef = new WeakReference(arg2);
        }

        public final void handleMessage(Message message) {
            a v0 = this.aRef.get();
            if (v0 != null) {
                b v1 = v0.d;
                if (v1 != null && !v0.isThreadInterrupted) {
                    switch (message.what) {
                        case 0:
                            v1.a();
                            return;
                        case 1:
                            v0.release();
                            v1.a((TTVideoError) message.obj);
                            return;
                        case 2:
                            v0.release();
                            v1.a(null, (TTVideoError) message.obj);
                            return;
                        case 3:
                            v0.release();
                            v1.a((String) message.obj, ((TTVideoError) null));
                            return;
                    }
                    return;
                }
            }
        }
    }

    protected Handler mHandler;
    protected boolean isThreadInterrupted = false;
    protected String c;
    protected b d;
    protected HttpRequest mHttpRequest;

    public a(String arg2) {
        this.mHttpRequest = null;
        this.c = arg2;
        this.mHandler = new WeakHandler(this);
    }

    public a(String arg2, HttpRequest httpRequest) {
        this.mHttpRequest = null;
        this.c = arg2;
        this.mHandler = new WeakHandler(this);
        if (httpRequest == null) {
            new OkHttpRequest();
        } else {
            this.mHttpRequest = httpRequest;
        }
    }

    public final void a(b arg1) {
        this.d = arg1;
    }

    protected final void a(String arg3) {
        this.mHandler.sendMessage(this.mHandler.obtainMessage(3, arg3));
    }

    public void b() {
    }

    protected final void b(TTVideoError ttVideoError) {
        this.mHandler.sendMessage(this.mHandler.obtainMessage(1, ttVideoError));
    }

    public void interrupt() {
    }

    protected final void onError(TTVideoError ttVideoError) {
        this.mHandler.sendMessage(this.mHandler.obtainMessage(2, ttVideoError));
    }

    public void release() {
    }

    protected final void e() {
        this.mHandler.sendEmptyMessage(0);
    }
}

